<template>
    <t-dialog :visible="dialogVisible" size="mini" @dialog-close="cancel">
      <div slot="title" class="app-service-center-content-charter-dismiss-dialog__title">{{ dialogTitle }}</div>
      <div slot="content" class="app-service-center-content-charter-dismiss-dialog__content">
        <div class="app-service-center-content-charter-dismiss-dialog__content">
          <div class="app-service-center-content-charter-dismiss-dialog__content__name__title"></div>
          <div class="app-service-center-content-charter-dismiss-dialog__content__name__value">  
            <t-textarea :autosize="propertyAutosize" :value="currentInputDismissReason" :focus="true" @input="handleCurrentInputDismissReason"></t-textarea>
          </div>
        </div>
      </div>
      <div slot="footer" style="text-align: right;">
      	<t-button size="normal" type="insert" @click="reject">驳回</t-button>
      </div>
    </t-dialog>
</template>

<script>
  import TDialog from '@/components/dialog';
  import TButton from '@/components/button';
  import TInput from '@/components/input';
  import TTextarea from '@/components/textarea';
  import TTable from '@/components/table';
  import TTableColumn from '@/components/table/table-column';
  
  export default {
    name: 'app-service-center-content-charter-dismiss-dialog',
    props: {
      store: {
        type: Object,
        required: true,
      },
    },
    components: {
      TButton,
      TInput,
      TTextarea,
      TTable,
      TTableColumn,
      TDialog,
    },
    data() {
      return {
        propertyAutosize: {
          minRows: 8,
          maxRows: 8,
        },
        depositAutosize: {
          minRows: 3,
          maxRows: 4,
        },
        financialAutosize: {
          minRows: 3,
          maxRows: 4,
        },
      };
    },
    computed: {
//    charters() {
//      return this.store.charters;
//    },
//    currentItem() {
//      return this.store.current.item;
//    },
      currentItemOtherAttrubutes() {
        if (this.store.current.item === null) return [];
        let attrs = [];
        attrs.push({ createDate: '用户编号', createDateVal: this.store.current.item.cusId });
        attrs.push({ createDate: '用户姓名', createDateVal: this.store.current.item.name });
        attrs.push({ createDate: '用户性别', createDateVal: this.store.current.item.sex === 'male' ? '男' : '女' });
        attrs.push({ createDate: '用户年龄', createDateVal: this.store.current.item.age });
        attrs.push({ createDate: '用户身份证', createDateVal: this.store.current.item.idCardNumber });
        attrs = attrs.reverse();
        return attrs;
      },
      currentInputDismissReason() {
        return this.store.current.input.dismissreason;
      },
//    currentInputDeposit() {
//      return this.store.current.input.deposit;
//    },
//    currentInputFinancial() {
//      return this.store.current.input.financial;
//    },
      dialogTitle() {
        return this.store.dismissDialog.title;
      },
      dialogVisible() {
        return this.store.dismissDialog.visible;
      },
    },
    mounted() {
    },
    methods: {
      handleCurrentInputDismissReason(val) {
        this.store.current.input.dismissreason = val;
      },
      cancel() {
        this.$emit('close');
      },
      reject() {
        const id = this.store.current.item.id;
        const target = this.$stateHub.rolename === 'MANAGER' ? 'api/manager/reject' : 'api/leader/reject';
        const reason = this.store.current.input.dismissreason;
        this.$http.request({
          url: target,
          method: 'post',
          data: {
            id,
            reason,
          },
          transformRequest: [(data) => {
            const encodeId = encodeURIComponent(data.id);
            const encodeReason = encodeURIComponent(data.reason);
            return `reason=${encodeReason}&id=${encodeId}`;
          }],
        }).then((response) => {
          this.store.charters = [];
          Object.values(response.data).forEach((item) => {
            this.store.charters.push({
              cusId: item.cusId,
              name: item.name,
              sex: item.sex,
              age: item.age,
              state: item.state,
              idCardNumber: item.idCardNumber,
              property: item.property,
              deposit: item.deposit,
              financial: item.financial,
              id: item.id,
            });
          });
          this.$emit('close');
        }).catch(() => {
        });
      },
//    deleteItem() {
//      const id = this.store.current.item.id;
//      this.store.charters = this.store.charters.filter((item) => {
//        return item.id !== id;
//      });
//      this.$emit('close');
//      const target = `api/charters/${id}/actions/delete`;
//      this.$http.request({
//        url: target,
//        method: 'post',
//      }).then(() => {
//      }).catch(() => {
//      });
//    },
//    updateItem() {
//      const id = this.store.current.item.id;
//      const name = this.store.current.input.name;
//      const synopsis = this.store.current.input.synopsis;
//      Object.values(this.store.charters).forEach((item) => {
//        if (item.id === id) {
//          item.name = name;
//          item.synopsis = synopsis;
//        }
//      });
//      this.$emit('close');
//      const target = `api/charters/${id}`;
//      this.$http.request({
//        url: target,
//        method: 'put',
//        data: {
//          name,
//          synopsis,
//        },
//        transformRequest: [(data) => {
//          const encodeName = encodeURIComponent(data.name);
//          const encodeSynopsis = encodeURIComponent(data.synopsis);
//          return `name=${encodeName}&synopsis=${encodeSynopsis}`;
//        }],
//      }).then(() => {
//      }).catch(() => {
//      });
//    },
//    createItem() {
//      const name = this.store.current.input.name;
//      const synopsis = this.store.current.input.synopsis;
//      const target = 'api/charters';
//      this.$http.request({
//        url: target,
//        method: 'post',
//        data: {
//          name,
//          synopsis,
//        },
//        transformRequest: [(data) => {
//          const encodeName = encodeURIComponent(data.name);
//          const encodeSynopsis = encodeURIComponent(data.synopsis);
//          return `name=${encodeName}&synopsis=${encodeSynopsis}`;
//        }],
//      }).then((response) => {
//        const item = response.data.payload;
//        const createDate = this.dateFormat(item.createTime);
//        const updateDate = this.dateFormat(item.updateTime);
//        this.store.charters.push({
//          index: this.store.charters.length + 1,
//          name: item.name,
//          createDate,
//          updateDate,
//          id: item.id,
//          synopsis: item.synopsis,
//        });
//        this.$emit('close');
//      }).catch(() => {
//      });
//    },
//    dateFormat(ut) {
//      const day = ut.dayOfMonth;
//      const dayValue = day < 10 ? `0${day}` : `${day}`;
//      return `${ut.year}-${ut.monthValue}-${dayValue}`;
//    },
    },
  };
</script>